import {
	createRouter,
	createWebHashHistory
}
from 'vue-router'

const routes = [{
		path: '/login',
		name: 'Login',
		component: import('../views/Login.vue')
	},
	{
		path: '/',
		name: 'Main',
		redirect: '/home',
		component: import('../views/Main.vue'),
		children: [{
				path: '/home',
				name: 'Home',
				
				component: import('../views/Home.vue'),
				meta: {
					title: '首页',
				}
			},
			{
				path: '/exam',
				name: 'Exam',
				component: import('../views/exam/Exam.vue'),
				meta: {
					title: '评分考核',
					isTab: true
				},
			},
			{
				path: '/examCheck',
				name: 'ExamCheck',
				component: import('../views/exam/ExamCheck.vue'),
				meta: {
					title: '查看评分',
					isTab: false
				},
			},
			{
				path: '/examAdd',
				name: 'ExamAdd',
				component: import('../views/exam/ExamAdd.vue'),
				meta: {
					title: '新建考核',
					isTab: true
				},
			},
			{
				path: '/examTask',
				name: 'ExamTask',
				component: import('../views/exam/examTask.vue'),
				meta: {
					title: '考核任务',
					isTab: true
				},
			},
			{
				path: '/examTemp',
				name: 'ExamTemp',
				component: import('../views/examTemplate/ExamTemplate.vue'),
				meta: {
					title: '考核模板',
					isTab: true
				},
			},
			{
				path: '/examTempAdd',
				name: 'ExamTempAdd',
				component: import('../views/examTemplate/ExamTemplateAdd.vue'),
				meta: {
					title: '新建模板',
					isTab: true
				},
			},
			{
				path: '/examTempUpdate',
				name: 'ExamTempUpdate',
				component: import('../views/examTemplate/ExamTemplateAdd.vue'),
				meta: {
					title: '编辑模板',
					isTab: true
				},
			},
			{
				path: '/examRank',
				name: 'ExamRank',
				component: import('../views/examRank/examRank.vue'),
				meta: {
					title: '评分标准库',
					isTab: true
				},
			},
			{
				path: '/examRankAdd',
				name: 'ExamRankAdd',
				component: import('../views/examRank/ExamRankAdd.vue'),
				meta: {
					title: '添加评分标准',
					isTab: true
				},
			},
			{
				path: '/examRankUpdate',
				name: 'ExamRankUpdate',
				component: import('../views/examRank/ExamRankAdd.vue'),
				meta: {
					title: '编辑评分标准',
					isTab: true
				},
			},
			{
				path: '/examEva',
				name: 'ExamEva',
				component: import('../views/examEva/ExamEva.vue'),
				meta: {
					title: '评分指标库',
					isTab: true
				},
			},
			{
				path: '/examEvaAdd',
				name: 'ExamEvaAdd',
				component: import('../views/examEva/ExamEvaAdd.vue'),
				meta: {
					title: '添加评分指标',
					isTab: true
				},
			},
			{
				path: '/examEvaMove',
				name: 'ExamEvaMove',
				component: import('../views/examEva/ExamEvaMove.vue'),
				meta: {
					title: '移动评分指标',
					isTab: true
				},
			},
			{
				path: '/user',
				name: 'User',
				component: import('../views/user/User.vue'),
				meta: {
					title: '用户管理',
					isTab: true
				}
			},
			{
				path: '/userAdd',
				name: 'UserAdd',
				component: import('../views/user/UserAddOrUpdate.vue'),
				meta: {
					title: '添加用户',
					isTab: true
				}
			},
			{
				path: '/userUpdate',
				name: 'UserUpdate',
				component: import('../views/user/UserAddOrUpdate.vue'),
				meta: {
					title: '编辑用户',
					isTab: true
				}
			},
			{
				path: '/userCheck',
				name: 'UserCheck',
				component: import('../views/user/UserCheck.vue'),
				meta: {
					title: '查看用户',
					isTab: true
				}
			},
		]
	},
	{
		path: '/examCheckInfo',
		name: 'ExamCheckInfo',
		component: import('../views/exam/ExamCheckInfo.vue'),
		props: true,
		meta: {
			title: '查看评分明细',
			isTab: false
		},
	},
	{
		path: "/404",
		name: "NotFound",
		component: import('../views/404.vue')
	},
	{
		path: '/:pathMatch(.*)*',
		redirect: "/404"
	}
]

const router = createRouter({
	history: createWebHashHistory(),
	routes
})
router.beforeEach((to, from, next) => {
	if (to.name != "Login") {
		let permissions = localStorage.getItem("permissions")
		if (permissions == null || permissions == "") {
			next({
				name: 'Login'
			})
		}
	}
	return next()
})

export default router
